public class Solve {
    // 旋转数组
    // https://www.nowcoder.com/practice/e19927a8fd5d477794dac67096862042?tpId=295&tqId=1024689&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public int[] solve (int n, int m, int[] a) {
        // write code here
        m %= n;
        reverseArray(a, 0, n-m-1);
        reverseArray(a, n-m, n-1);
        reverseArray(a, 0, n-1);
        return a;
    }

    private void reverseArray(int[] a, int left, int right) {
        for (; left < right; left++, right--) {
            int tmp = a[left];
            a[left] = a[right];
            a[right] = tmp;
        }
    }
}
